package com.way.designpatterncodepratice.factory.abstractFactory;

import com.way.designpatterncodepratice.factory.base.Pizza;
import com.way.designpatterncodepratice.factory.factoryMethod.AbstractMethodFactory;

import java.util.Scanner;

/**
 * @author liangliwei 80551025
 * @description
 * @date 2020-06-22
 */
public class ChinaPizzaStore {

    private AbstractFactory abstractMethodFactory;
    Pizza pizza;

    public ChinaPizzaStore(AbstractFactory abstractMethodFactory) {
        this.abstractMethodFactory = abstractMethodFactory;
    }

    public void orderPizza(){
        while (true){
            String pizzaType = getType();
            pizza = abstractMethodFactory.cretePizza(pizzaType);

            /**
             * 输出pizza制作过程
             */
            if(pizza!=null){
                pizza.prepare();
                pizza.cut();
                pizza.bake();
                pizza.box();
            }else{
                System.out.println("订购失败");
                break;
            }
        }
    }

    private String getType() {
        Scanner scanner = new Scanner(System.in);
        String pizzaType = scanner.next();
        return pizzaType;
    }
}
